﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TreasureBox.Utility;

namespace TreasureBox
{
    public partial class RegGmails : Form
    {
        public RegGmails()
        {
            InitializeComponent();
        }
        public string LastName, FirstName, Email, Passwd, PasswdAgain, Questions, IdentityAnswer, SecondaryEmail;
        private void SendInformationAuto()
        {
            string fillInfo = RandomString.GenerateRandomString(12);
            LastName = FirstName = IdentityAnswer = fillInfo;
            Passwd = PasswdAgain = RandomNumber.GenerateRandomNumber("Pwd01!", 99999999, 10000000);
            Email = RandomNumber.GenerateRandomNumber("BGA", 999999999, 100000000);
            SecondaryEmail = "";

            HtmlElementCollection htmlElementCollection = webReg.Document.GetElementsByTagName("input");
            for (int i = 0; i < htmlElementCollection.Count; i++)
            {
                string temp = htmlElementCollection[i].GetAttribute("name");
                switch (htmlElementCollection[i].GetAttribute("name"))
                {
                    case "LastName":
                        htmlElementCollection[i].SetAttribute("value", LastName);
                        break;
                    case "FirstName":
                        htmlElementCollection[i].SetAttribute("value", FirstName);
                        break;
                    case "Email":
                        htmlElementCollection[i].SetAttribute("value", Email);
                        htmlElementCollection[i].InvokeMember("keyup");
                        break;
                    case "Passwd":
                        htmlElementCollection[i].SetAttribute("value", Passwd);
                        break;
                    case "PasswdAgain":
                        htmlElementCollection[i].SetAttribute("value", PasswdAgain);
                        break;
                    case "IdentityAnswer":
                        htmlElementCollection[i].SetAttribute("value", IdentityAnswer);
                        break;

                    case "SecondaryEmail":
                        htmlElementCollection[i].SetAttribute("value", SecondaryEmail);
                        break;
                }
            }
            htmlElementCollection = webReg.Document.GetElementsByTagName("select");
            for (int i = 0; i < htmlElementCollection.Count; i++)
            {
                switch (htmlElementCollection[i].GetAttribute("id"))
                {
                    case "questions":
                        htmlElementCollection[i].Children[3].SetAttribute("selected", "selected");
                        break;
                    case "loc":

                        for (int K = 0; K < htmlElementCollection[i].Children.Count; K++)
                        {
                            if (htmlElementCollection[i].Children[K].InnerText.IndexOf("China") > 0)
                            {
                                htmlElementCollection[i].Children[K].SetAttribute("selected", "selected");
                            }
                        }

                        break;
                }
            }

            htmlElementCollection = webReg.Document.GetElementsByTagName("div");
            for (int i = 0; i < htmlElementCollection.Count; i++)
            {
                switch (htmlElementCollection[i].GetAttribute("id"))
                {
                    case "passwdRating":
                        //htmlElementCollection[i].InnerHtml = "<font><b><font color=\"#008000\">Strong</font></b></font>";
                        break;
                }
            }

            FileProcess.AppendingFile("gmaillog.txt", Email + "@gmail.com", Passwd);
        }

        private void webReg_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            SendInformationAuto();
        }
    }
}
